package com.wxy.demo.service;

import com.wxy.demo.dao.UserRepository;
import com.wxy.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangxiaoyuan
 * 2021/6/24 10:23
 **/
@Service
@Transactional
public class UserService {

    @Autowired
    public UserRepository userRepository;


    /**
     * 查询所有用户
     *
     * @return
     */
    @Transactional(readOnly = true)
    public List<User> findAll() {
        List<User> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            User user = new User("zhangsan" + i, i + "123@qq.com");
            list.add(user);
        }
        userRepository.saveAll(list);
        return userRepository.findAll();
    }
}
